package com.jz.community.basecomm.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.jz.community.basecomm.mvp.BaseMvpPresenter;
import com.jz.community.basecomm.mvp.MVPContract;

import butterknife.ButterKnife;

/**
 * Created by Tony.Fan on 2018/3/15 13:48
 */
public abstract class BaseMvpSupportActivity<V extends MVPContract.View, P extends BaseMvpPresenter<V>> extends AppCompatActivity {

    protected P mPresenter;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getContentView());
        ButterKnife.bind(this);
        initPresenter();

        initView();
        addListener();
        initDatas();
    }

    protected void addListener() {

    }

    private void initPresenter() {
        if (mPresenter == null) {
            mPresenter = createPresenter();
        }
    }


    /**
     * 设置ContentView
     *
     * @return
     */
    protected abstract int getContentView();

    /**
     * 初始化数据
     */
    protected void initDatas() {

    }

    /**
     * 初始化View
     */
    protected void initView() {

    }

    protected abstract P createPresenter();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.detachView();
        }
    }
}
